package great.project.service.test.tranal;

import great.project.mapper.Test1Mapper;
import great.project.pojo.entity.Test1;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * <div  style="border:2px solid none;margin:20px;padding:15px;font-size:24px;text-align:center;color:aqua;">
 *
 *
 *
 *  </div>
 *
 * @author RichMan
 * @date 2021-03-28 23:38
 */
@Service
public class TransactionService implements TransactionInterface {

    @Resource
    private Test1Mapper test1Mapper;

    @Autowired
    private TransactionService transactionService;

//    @Transactional(rollbackFor = Exception.class)
    @Override
    public void t() {

//        test1Mapper.insert(Test1.builder().id(1).name("A").build());

        transaction1Service.testPrivate(-1);

        transaction1Service.testPublic(1);

//        testPrivate(4);
//
//        testPublic(5);
//
//        this.testThisPrivate(6);
//
//        this.testThisPublic(7);

//        throw new RuntimeException("123");

    }

    @Resource
    private Transaction1Service transaction1Service;

    @Transactional(rollbackFor = Exception.class)
    public void testPrivate(int isThrow) {
        test1Mapper.insert(Test1.builder().id(2).name("" + isThrow).build());

    }

    @Transactional(rollbackFor = Exception.class)
    public void testPublic(int isThrow) {
        test1Mapper.insert(Test1.builder().id(3).name("" + isThrow).build());

    }

    @Transactional(rollbackFor = Exception.class)
    public void testThisPublic(int isThrow) {
        test1Mapper.insert(Test1.builder().id(4).name("" + isThrow).build());

    }

    @Transactional(rollbackFor = Exception.class)
    private void testThisPrivate(int isThrow) {
        test1Mapper.insert(Test1.builder().id(5).name("" + isThrow).build());

    }

}
